package com.yonyou.cloud.member.adapters.dto;

import com.yonyou.cloud.member.exceptions.NotSupportedException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(description = "返回结果")
@lombok.Data
public class ApiResponseDto<T> {
    @ApiModelProperty(value = "状态码,200表示成功，非200表示错误码")
    private String code;
    @ApiModelProperty(value = "提示信息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private T data;

    public ApiResponseDto(boolean success) {
        if (success) {
            this.code = "200";
        } else {
            throw new NotSupportedException("ApiResponseDto.constructor only supports true");
        }
    }

    public ApiResponseDto(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public ApiResponseDto setData(T data) {
        this.data = data;
        return this;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
